package com.htht.job.executor.service;

import com.htht.job.core.api.DubboShiroService;
import com.htht.job.executor.model.shiro.Resource;
import com.htht.job.executor.model.shiro.Role;
import com.htht.job.executor.model.shiro.User;
import com.htht.job.executor.model.tree.ZtreeView;
import com.htht.job.executor.service.shiro.ResourceService;
import com.htht.job.executor.service.shiro.RoleService;
import com.htht.job.executor.service.shiro.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by zzj on 2018/1/24.
 */
@Transactional
@Service("dubboShiroService")
public class DubboShiroServiceImpl implements DubboShiroService {
    @Autowired
    private ResourceService resourceService;
    @Autowired
    private RoleService roleService;
    @Autowired
    private UserService userService;

    public String findByUserName(String username){
        return userService.findByUserName(username);
    }
    public void saveOrUpdateUser(User user){
         userService.saveOrUpdate(user);
    }
    public void deleteUser(String id){
         userService.delete(id);
    }
    public void grantUser(String id, String[] roleIds){
         userService.grant(id,roleIds);
    }
    public void saveOrUpdateRole(Role role){
         roleService.saveOrUpdate(role);
    }
    public void deleteRole(String id){
         roleService.delete(id);
    }
    public void grantResoure(String id, String[] resourceIds){
         roleService.grant(id,resourceIds);
    }
    public List<ZtreeView> tree(String roleId){
        return  resourceService.tree(roleId);
    }
    public void saveOrUpdateResource(Resource resource){
        resourceService.saveOrUpdate(resource);
    }
    public void deleteResource(String id){
        resourceService.delete(id);
    }
    public String userList(int start, int length, String searchText){
        return  userService.list(start,length,searchText);
    }
    public String roleList(int start, int length, String searchText){
        return  roleService.list(start,length,searchText);
    }
    public String resourceList(int start, int length, String searchText){
        return  resourceService.list(start,length,searchText);
    }

    public String findAllResouce(){
        return resourceService.findAllResouce();
    }
    public List<ZtreeView> allTree(){
        return resourceService.allTree();
    }
    public String findById(String id){
        return userService.findById(id);
    }
    public String findAllRole(){
        return roleService.findAllRole();
    }
}
